/**
 * @author Stephan Pfaff (http://www.derdaumen.net)
 */

/**
 * wenn true, Fehlermeldungen ausgeben
 */
var debug = true;
/**
 * Site Objekt
 */
var site = null;
/**
 * wenn true, Funktionalität ohne PHP, ausschließlich über JavaScript und AJAX
 */
var noPHPMode = true;
/**
 * wenn true, werden buttons verrückbar
 */
var allowDraggable = false;
/**
 * wenn true, wird der Content nach einem klick ausgeblendet und eingefadet
 */
var fadeContent = false;


var imageRoot = 'images/';
var url = location.href;
var urlTemp = url.substring(0, url.lastIndexOf('/'));
var siteRoot = url.substring(0, urlTemp.lastIndexOf('/')+1);


/**
 * Die Site Klasse
 */
function Site(div){
	this.gridSize = 80;
	this.grid_w = 6;
	this.grid_h = 5;
	this.navAnimationDuration = 500;
	this.btnAnimationDuration = 300;
	this.containerFadeDuration = 1000;
	this.libPath = 'lib/php/';
	this.preface = this.getPreface();
	this.categories = this.getCategories();
	this.projects = this.getProjects();
	this.buttons = this.getButtons();
	this.$div = $(div);
};
/**
 * Abstand zwischen den selben Seiten zweier Gitterkästchen
 */
Site.prototype.gridSize = null;
/**
 * Horizontale Kästchenanzahl
 */
Site.prototype.grid_w = null;
/** 
 * Vertikale Kästchenanzahl
 */
Site.prototype.grid_h = null;
/** 
 * Dauer der Fade Animationen
 */
Site.prototype.navAnimationDuration = null;
/** 
 * Dauer der Container Fade Animationen
 */
Site.prototype.containerFadeDuration = null;
/**
 * Pfad zu den PHP Scripten
 */
Site.prototype.libPath = null;
/**
 * Der Preface Container
 */
Site.prototype.preface = null;
/**
 * Der Kategorie Container
 */
Site.prototype.categories = null;
/**
 * Der Projekte Container
 */
Site.prototype.projects = null;
/**
 * Der Content-Buttons Container
 */
Site.prototype.buttons = null;
/**
 * Das Jquery Objekt des main content divs
 */
Site.prototype.$div = null;

/**
 * Preface Getter
 * @return ItemContainer preface
 */
Site.prototype.getPreface = function(){
	if(this.preface == null) {
		this.preface = new ItemContainer('preface',
				'pre',
				this.libPath+'load.php');
	}
	return this.preface;
};
/**
 * Categories Getter
 * @return ItemContainer categories
 */
Site.prototype.getCategories = function(){
	if(this.categories == null) {
		this.categories = new ItemContainer('category',
				'ctg',
				this.libPath+'load.php');
	}
	return this.categories;
};
/**
 * Projects Getter
 * @return ItemContainer projects
 */
Site.prototype.getProjects = function(){
	if(this.projects == null) {
		this.projects = new ItemContainer('project',
				'prj',
				this.libPath+'load.php');
	}
	return this.projects;
};
/**
 * Buttons Getter
 * @return ItemContainer buttons
 */
Site.prototype.getButtons = function(){
	if(this.buttons == null) {
		this.buttons = new ItemContainer('button',
				'btn',
				this.libPath+'load.php');
	}
	return this.buttons;
};
/**
 * Animiert das Text-Intro der Seite und fadet danach die Seite ein.
 * @return void
 */
Site.prototype.animateIntro = function() {
	$('body').append('<div id="intro_animation" style="display: none;"><span class="logo_part1">Kuner</span> <span class="logo_part2">Architekten</span></div>');
	$('#intro_animation').fadeIn(1000).delay(2000).fadeOut(1000, function(){
		$(this).remove();
		site.$div.fadeIn(site.navAnimationDuration);
	});
};
/**
 * Lädt die Inhalte des Preface oder der Startseite
 * @param params Object - Parameter Objekt: {prefix, ctg_id und prj_id}
 * @return void
 */
Site.prototype.load = function(params) {
	if(params.ctg_id == null) {
		this.preface.load(params, false);
		site.animateIntro();
	} else {
		this.categories.load(params, false);
	}
};
/**
 * Site Getter
 * @param div String - die id des Divs welches den gesamten Content enthält.
 * @return Site site
 */
function getSite(div) {
	if(site == null) {
		site = new Site(div);
	}
	return site;
}
/**
 * Initialisiert die Seite.
 * Blendet den Content-Container Div aus, falls die Startseite aufgerufen wird. 
 * @param params Object - Parameter Objekt: {prefix, ctg_id und prj_id}
 * @return void
 */
function init(params) {
	if(params.ctg_id == null)
		$('#main').hide();
	//PHP Scrolling - unfinished
	/*
	$('#projectUp').remove();
	$('#projectDown').remove();
	*/
	site = getSite('#main');
	site.load(params);
	
	/*Shadowbox.init({
	    // skip the automatic setup again, we do this later manually
	    skipSetup: true
	});*/
}